package org.ch04.test00.demo01;

import java.lang.reflect.Field;

/**
 * @author CSY
 * @date 2025 - 03 - 28
 */
public class CheckAge {
    public static Integer checkAge(Class<?> clazz,int age) {
        Field ageField = null;
        try {
            ageField = clazz.getDeclaredField("age");
            ageField.setAccessible(true);
            SetValue annotation = ageField.getAnnotation(SetValue.class);
            int annotationAge = annotation.value();
            if(age < annotationAge){
                throw new Exception("年龄不能小于"+annotationAge+"岁");
            }
            return age;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }

}
